package org.wanda.pv.controller.business;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.wanda.pv.framework.base.Result;
import org.wanda.pv.model.business.Mark;
import org.wanda.pv.model.business.MarkExaminesContent;
import org.wanda.pv.model.hy.HyUserInfo;
import org.wanda.pv.service.business.MarkExaminesContentService;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lxy
 * Created by 2019/1/8 10:50
 */
@RestController
@RequestMapping("/business/markExaminesContent")
public class MarkExaminesContentController {
	@Autowired
	private MarkExaminesContentService markExaminesContentService;

	@Autowired
	private Dao dao;

	@RequestMapping(value = "/addMarkExaminesContent", method = RequestMethod.POST)
	public Object addMarkExaminesContent(HttpServletRequest request, Long markId, String roleType , String content) {
		// 获取用户信息 ， 判断用户信息是否符合回复的角色
		MarkExaminesContent markExaminesContent = null;
		HyUserInfo hyUserInfo = (HyUserInfo) request.getSession().getAttribute("userInfo");
		if (hyUserInfo == null) {
			return Result.error("获取不到用户信息，请重新登录！", "获取不到用户信息，请重新登录 ！");
		}
		    if (!hyUserInfo.getHyRole().getRoleType().equals(roleType)){
				return Result.error("当前用户和权限不匹配！","当前用户和权限不匹配！");
			}
			if(markId == null){
				return Result.error("当前使用标注不存在！","当前使用标注不存在！");
			}
			Mark mark = dao.fetch(Mark.class, markId);
			if (mark == null) {
				return Result.error("当前使用标注不存在！","当前使用标注不存在！");
			}
		return  markExaminesContentService.add(content,hyUserInfo , mark);
	}

	@RequestMapping("/getMarkExaminesContentByMarkId")
	public Result getMarkExaminesContentByMarkId(Long markId) {
		MarkExaminesContent markExaminesContent = null;
		if(markId == null){
			return Result.error("当前使用标注不存在！","当前使用标注不存在！");
		} else {
			Mark mark = dao.fetch(Mark.class,markId);
			if (mark == null ){
				return Result.error("当前使用标注不存在！","当前使用标注不存在！");
			}
		}
		markExaminesContent = markExaminesContentService.getMarkExaminesContentByMarkId(markId);
		return Result.success("success",markExaminesContent);
	}


}
